import React, { useState } from 'react';
import { useHistory } from 'react-router-dom'
import { message } from "antd";
import { loginCheckApi } from "../../../api/admin";
import '../Login/index.css'

export default function () {
    const [name, setName] = useState("李欢")
    const [pass, setPass] = useState("123")
    const history = useHistory();

    const loginCheck = () => {
        loginCheckApi({ name, pass })
            .then(res => {
                if (res.data.length == 1) {
                    message.success('登录成功！');
                    // 1、保存用户名
                    // 2、token
                    // 3、权限
                    sessionStorage.setItem("grants", JSON.stringify(res.data[0].checkedKeys));
                    history.push("/Main");
                }
            })
    }
    return (
        <div className='login'>
            <div>
                <div className='min-box'>
                    <p className='tet1'>THINK · 智慧校园</p>
                    <p className='tet2'>后台管理系统</p>
                    <div className='txte'>
                        <input placeholder='请输入账号' className='txt' type="text" value={name} onChange={e => setName(e.target.value)} />
                    </div>
                    <div className='txte'>
                        <input placeholder='请输入密码' className='txt' type="password" value={pass} onChange={e => setPass(e.target.value)} />
                    </div>
                    <div className='chk'>
                                <input type='radio' /> <label>我已阅读并同意</label><span className='s1'>《THINK智慧校园用户协议》</span>
                            </div>
                    <input type="button" value="登录" onClick={loginCheck} className='btn' />
                </div>
            </div>
        </div>

    )
}
